home *** CD-ROM | disk | FTP | other *** search
/ Mac Format 1994 October / Macformat17.cdr / Shareware City / Developers / shutdown-fx-20-c / sfx control app ƒ / sfx code ƒ / sfx meat.c < prev    next >
Text File  |  1994-07-11  |  8KB  |  337 lines

  1. /**********************************************************************\
  2.  
  3. File:        sfx meat.c
  4.  
  5. Purpose:    This module handles the fade modules folder: setting up
  6.             the two lists based on the initial information, setting
  7.             information of fades.
  8.  
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13.  
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. GNU General Public License for more details.
  18.  
  19. You should have received a copy of the GNU General Public License
  20. along with this program in a file named "GNU General Public License".
  21. If not, write to the Free Software Foundation, 675 Mass Ave,
  22. Cambridge, MA 02139, USA.
  23.  
  24. \**********************************************************************/
  25.  
  26. #include "Folders.h"
  27. #include "sfx meat.h"
  28. #include "sfx install.h"
  29. #include "sfx gestalt.h"
  30. #include "sfx lists.h"
  31. #include "main.h"
  32. #include "timing.h"
  33. #include "util.h"
  34. #include "file interface.h"
  35.  
  36. struct QDGlobals
  37. {
  38.     char privates[76];
  39.     long randSeed;
  40.     BitMap screenBits;
  41.     Cursor arrow;
  42.     Pattern dkGray;
  43.     Pattern ltGray;
  44.     Pattern gray;
  45.     Pattern black;
  46.     Pattern white;
  47.     GrafPtr thePort;
  48.     long    end;
  49. };
  50.  
  51. typedef struct QDGlobals QDGlobals;
  52. typedef pascal short (*FadeProcPtr)(Rect boundsRect, Pattern *thePattern);
  53.  
  54. long            gModuleDirID;
  55. short            gModuleVRefNum;
  56.  
  57. /* internal procedures for use in sfx meat.c only */
  58. static OSErr TouchFolder(FSSpec fs);
  59. static void DoTheDangFade(FadeProcPtr theFade);
  60.  
  61.  
  62. enum ErrorTypes SetUpLists(ListHandle usedList, ListHandle unusedList)
  63. {
  64.     CInfoPBRec        pb;
  65.     OSErr            isHuman;
  66.     Str255            theName;
  67.     long            systemDirID;
  68.     short            numModules;
  69.     short            i;
  70.     Boolean            noModules;
  71.     
  72.     isHuman=FindFolder(kOnSystemDisk, kSystemFolderType, kDontCreateFolder, &gModuleVRefNum,
  73.                 &systemDirID);                    /* find system folder */
  74.     if (isHuman!=noErr)
  75.         return kCantFindSystemFolder;
  76.     
  77.     pb.dirInfo.ioCompletion=0L;
  78.     pb.dirInfo.ioNamePtr=MODULE_FOLDER;
  79.     pb.dirInfo.ioVRefNum=gModuleVRefNum;
  80.     pb.dirInfo.ioFDirIndex=0;             /* very important */
  81.     pb.dirInfo.ioDrDirID=systemDirID;
  82.     isHuman=PBGetCatInfo(&pb, FALSE);    /* get info on "MSG Fades ƒ" folder */
  83.     if (isHuman!=noErr)
  84.         return kCantFindModuleFolder;
  85.     
  86.     gModuleDirID=pb.dirInfo.ioDrDirID;
  87.     numModules=pb.dirInfo.ioDrNmFls;
  88.     
  89.     MyClearAllCells(usedList);
  90.     MyClearAllCells(unusedList);
  91.     
  92.     noModules=TRUE;
  93.     
  94.     for (i=1; i<=numModules; i++)
  95.     {
  96.         pb.hFileInfo.ioCompletion=0L;
  97.         pb.hFileInfo.ioNamePtr=theName;
  98.         pb.hFileInfo.ioVRefNum=gModuleVRefNum;
  99.         pb.hFileInfo.ioFDirIndex=i;
  100.         pb.hFileInfo.ioDirID=gModuleDirID;
  101.         isHuman=PBGetCatInfo(&pb, FALSE);
  102.         if ((isHuman==noErr) && (!(pb.hFileInfo.ioFlAttrib&0x10)) &&
  103.             (pb.hFileInfo.ioFlFndrInfo.fdCreator==CREATOR))
  104.         {
  105.             /* got a fade module, now find out if it's used or unused and add to list */
  106.             
  107.             if (pb.hFileInfo.ioFlFndrInfo.fdType==USED_TYPE)
  108.             {
  109.                 MyAddStr255ToList(usedList, theName);
  110.                 noModules=FALSE;
  111.             }
  112.             else if (pb.hFileInfo.ioFlFndrInfo.fdType==UNUSED_TYPE)
  113.             {
  114.                 MyAddStr255ToList(unusedList, theName);
  115.                 noModules=FALSE;
  116.             }
  117.         }
  118.     }
  119.     
  120.     return noModules ? kNoModulesInFolder : allsWell;
  121. }
  122.  
  123. enum ErrorTypes DoTheDemoFade(ListHandle theList)
  124. {
  125.     Cell            theCell;
  126.     Str255            theName;
  127.     Handle            theProcHandle;
  128.     FadeProcPtr        theFade;
  129.     unsigned long    theSize;
  130.     FSSpec            fs;
  131.     short            oldRefNum, newRefNum;
  132.     Boolean            alreadyOpen;
  133.     OSErr            theResError;
  134.     
  135.     if (!MyGetFirstSelectedCell(theList, &theCell))
  136.         return allsWell;
  137.     
  138.     while (LGetSelect(TRUE, &theCell, theList))
  139.     {
  140.         MyGetCellData(theList, theCell, theName);
  141.         LNextCell(FALSE, TRUE, &theCell, theList);
  142.         MyMakeFSSpec(gModuleVRefNum, gModuleDirID, theName, &fs);
  143.         theResError=OpenTheResFile(&fs, &oldRefNum, &newRefNum, &alreadyOpen);
  144.         if (theResError!=noErr)
  145.             return kCantOpenModule;
  146.         
  147.         theProcHandle=Get1Resource('PROC', 0);
  148.         if (((theResError=ResError())!=noErr) || (theProcHandle==0L))
  149.             return kModuleDamaged;
  150.         
  151.         if (*theProcHandle==0L)
  152.             LoadResource(theProcHandle);
  153.         if (*theProcHandle==0L)
  154.             return kModuleDamaged;
  155.         
  156.         HLock(theProcHandle);
  157.         theFade=NewPtrSys(theSize=GetHandleSize(theProcHandle));
  158.         Mymemcpy(theFade, *theProcHandle, theSize);
  159.         ReleaseResource(theProcHandle);
  160.         theProcHandle=0L;
  161.         CloseTheResFile(oldRefNum, newRefNum, alreadyOpen);
  162.         DoTheDangFade(theFade);
  163.         DisposePtr(theFade);
  164.         theFade=0L;
  165.         while (HandleSingleEvent());
  166.     }
  167.     
  168.     return allsWell;
  169. }
  170.  
  171. void DoTheDangFade(FadeProcPtr theFade)
  172. {
  173.     short            oldMenuBarHeight;
  174.     long            oldA5;
  175.     QDGlobals        qd;                /* our QD globals. */
  176.     GrafPort        gp;                /* our grafport. */
  177.     GrafPtr            savePort;
  178.     short            whichWipe;
  179.     THz                saveZone;
  180.     unsigned long    temp;
  181.     
  182.     GetPort(&savePort);
  183.     oldMenuBarHeight=MBarHeight;
  184.     MBarHeight=0;
  185.     DrawMenuBar();
  186.  
  187.     /* get a value for A5, a structure that mirrors qd globals. */
  188.     oldA5 = SetA5((long)&qd.end);
  189.     InitGraf(&qd.thePort);
  190.     OpenPort(&gp);
  191.     
  192.     HideCursor();
  193.     
  194.     saveZone=GetZone();
  195.     SetZone(SysZone);
  196.  
  197.     theFade(gp.portRect, &qd.black);
  198.     
  199.     SetZone(saveZone);
  200.     
  201.     MBarHeight=oldMenuBarHeight;
  202.     ShowCursor();
  203.     ObscureCursor();
  204.     
  205.     ClosePort(&gp);
  206.     SetA5(oldA5);
  207.     SetPort(savePort);
  208.     
  209.     StartTiming();
  210.     TimeCorrection(10);
  211.     
  212.     DrawMenuBar();
  213.     PaintOne(0L, GetGrayRgn());
  214.     PaintBehind(WindowList, GetGrayRgn());
  215. }
  216.  
  217. enum ErrorTypes DoTheInstall(WindowDataHandle theData, ListHandle usedList,
  218.     ListHandle unusedList)
  219. {
  220.     Cell            theCell;
  221.     CInfoPBRec        pb;
  222.     OSErr            isHuman;
  223.     Str255            theName;
  224.     GrafPtr            curPort;
  225.     FSSpec            fs;
  226.     
  227.     if (!MyGetFirstSelectedCell(unusedList, &theCell))
  228.         return allsWell;
  229.     
  230.     while (LGetSelect(TRUE, &theCell, unusedList))
  231.     {
  232.         MyGetCellData(unusedList, theCell, theName);
  233.         LNextCell(FALSE, TRUE, &theCell, unusedList);
  234.         pb.hFileInfo.ioCompletion=0L;
  235.         pb.hFileInfo.ioNamePtr=theName;
  236.         pb.hFileInfo.ioVRefNum=gModuleVRefNum;
  237.         pb.hFileInfo.ioFDirIndex=0;
  238.         pb.hFileInfo.ioDirID=gModuleDirID;
  239.         isHuman=PBGetCatInfo(&pb, FALSE);
  240.         if (isHuman!=noErr)
  241.             return kCantGetModuleInfo;
  242.         
  243.         pb.hFileInfo.ioDirID=gModuleDirID;
  244.         pb.hFileInfo.ioFlFndrInfo.fdType=USED_TYPE;
  245.         isHuman=PBSetCatInfo(&pb, FALSE);
  246.         if (isHuman!=noErr)
  247.             return kCantSetModuleInfo;
  248.     }
  249.     
  250.     MyMakeFSSpec(gModuleVRefNum, gModuleDirID, theName, &fs);
  251.     TouchFolder(fs);
  252.     
  253.     LDoDraw(FALSE, usedList);
  254.     LDoDraw(FALSE, unusedList);
  255.     SetUpLists(usedList, unusedList);
  256.     LDoDraw(TRUE, usedList);
  257.     LDoDraw(TRUE, unusedList);
  258.     GetPort(&curPort);
  259.     SetPort((**unusedList).port);
  260.     EraseRect(&((**unusedList).rView));
  261.     SetPort(curPort);
  262.     
  263.     return allsWell;
  264. }
  265.  
  266. enum ErrorTypes DoTheRemove(WindowDataHandle theData, ListHandle usedList,
  267.     ListHandle unusedList)
  268. {
  269.     Cell            theCell;
  270.     CInfoPBRec        pb;
  271.     OSErr            isHuman;
  272.     Str255            theName;
  273.     GrafPtr            curPort;
  274.     FSSpec            fs;
  275.     
  276.     if (!MyGetFirstSelectedCell(usedList, &theCell))
  277.         return allsWell;
  278.     
  279.     while (LGetSelect(TRUE, &theCell, usedList))
  280.     {
  281.         MyGetCellData(usedList, theCell, theName);
  282.         LNextCell(FALSE, TRUE, &theCell, usedList);
  283.         pb.hFileInfo.ioCompletion=0L;
  284.         pb.hFileInfo.ioNamePtr=theName;
  285.         pb.hFileInfo.ioVRefNum=gModuleVRefNum;
  286.         pb.hFileInfo.ioFDirIndex=0;
  287.         pb.hFileInfo.ioDirID=gModuleDirID;
  288.         isHuman=PBGetCatInfo(&pb, FALSE);
  289.         if (isHuman!=noErr)
  290.             return kCantGetModuleInfo;
  291.         
  292.         pb.hFileInfo.ioDirID=gModuleDirID;
  293.         pb.hFileInfo.ioFlFndrInfo.fdType=UNUSED_TYPE;
  294.         isHuman=PBSetCatInfo(&pb, FALSE);
  295.         if (isHuman!=noErr)
  296.             return kCantSetModuleInfo;
  297.     }
  298.     
  299.     MyMakeFSSpec(gModuleVRefNum, gModuleDirID, theName, &fs);
  300.     TouchFolder(fs);
  301.     
  302.     LDoDraw(FALSE, usedList);
  303.     LDoDraw(FALSE, unusedList);
  304.     SetUpLists(usedList, unusedList);
  305.     LDoDraw(TRUE, usedList);
  306.     LDoDraw(TRUE, unusedList);
  307.     GetPort(&curPort);
  308.     SetPort((**usedList).port);
  309.     EraseRect(&((**usedList).rView));
  310.     SetPort(curPort);
  311.     
  312.     return allsWell;
  313. }
  314.  
  315. OSErr TouchFolder(FSSpec fs)
  316. {
  317.     CInfoPBRec        pb;
  318.     OSErr            isHuman;
  319.     
  320.     pb.dirInfo.ioCompletion=0L;
  321.     pb.dirInfo.ioVRefNum=fs.vRefNum;
  322.     pb.dirInfo.ioDrDirID=fs.parID;
  323.     pb.dirInfo.ioNamePtr=fs.name;
  324.     pb.dirInfo.ioFDirIndex=0;
  325.     if ((isHuman=PBGetCatInfo(&pb, FALSE))!=noErr)
  326.     {
  327.         FlushVol(0L, fs.vRefNum);
  328.         pb.dirInfo.ioDrDirID=pb.dirInfo.ioDrParID;
  329.         pb.dirInfo.ioFDirIndex=0;
  330.         GetDateTime(&(pb.dirInfo.ioDrMdDat));
  331.         isHuman=PBSetCatInfo(&pb, FALSE);
  332.         FlushVol(0L, fs.vRefNum);
  333.     }
  334.     
  335.     return isHuman;
  336. }
  337.